import { createRouter, createWebHistory } from 'vue-router'
import { routes } from './routerPath.ts'
import { useUserStore } from "../store";

const router = createRouter({
  history: createWebHistory(),
  routes
})
//全局导航守卫
router.beforeEach((to, from, next) => {
  console.log('to', to, 'from', from, 'next', next)
  const user = useUserStore().user
  if(to.path != '/login' && !user?.id){
    next({ path: '/login' })
  }
  next()
})
router.beforeEach(() => {

})
export default router
